/**
 * Created by sakuri on 2017/4/12
 */
;-function (window) {
    "use strict";
    //预设变量写这里，全局变量写在base.js 里面 使用 r. 调用
    var ready = {
        right_chart_tab_1: null,
        right_chart_tab_2: null,
        index_court: null,
        judge: [],
        judge_name: [],
        now_dept: null,
        dept: [],
        dept_name: [],
        now_judge: [],
        now_one_judge: null,
        now_judge_name: [],
        courtrooms: [],
        courtrooms_name: [],
        init_date: null,
        status_value: "0",//记录当前选择的左侧标签
        count_start_time: null,//记录案件查询时查询总数的时间段
        count_end_time: null,
        right_chart_tab_width: null,
        right_chart_tab_height: null,
        webSocket: null,
        more_review_trial: null
    };
    //初始化的方法写这里面
    var init = function () {
        Class.draw();//绘制页面
        init_ready();//加载预设变量
        Class.select_dept_group();//初始化左侧列表数据
        init_event();
        function init_event() {//初始化页面事件
            //时间插件预设为今年
            $('#startTime').datetimepicker({
                bootcssVer: 3,
                minView: "month", //选择日期后，不会再跳转去选择时分秒
                weekStart: "1",
                format: "yyyy-mm-dd", //选择日期后，文本框显示的日期格式
                language: 'zh-CN', //汉化
                autoclose: true //选择日期后自动关闭
            }).on('changeDate', function (ev) {
                console.log(ev.date.valueOf());
            });
            $('#endTime').datetimepicker({
                bootcssVer: 3,
                minView: "month", //选择日期后，不会再跳转去选择时分秒
                weekStart: "1",
                format: "yyyy-mm-dd", //选择日期后，文本框显示的日期格式
                language: 'zh-CN', //汉化
                autoclose: true //选择日期后自动关闭
            }).on('changeDate', function (ev) {
                console.log(ev.date.valueOf());
            });
            $("#endTime").find("input").val(utils.get_date(0));
            $("#startTime").find("input").val(new Date().getFullYear() + "-01-01");
            // Class.init_verify_count();
            $("#submitButton").click(function () {
                //获取当前是排期或者回顾
                var status_tab = $(".cmp-left-tabs").find(".active").find("a").html();
                if ("庭审排期" == status_tab) {
                    ready.status_value = "0";
                } else if ("庭审回顾" == status_tab) {
                    ready.status_value = "1";
                } else {
                    ready.status_value = "2";
                }
                Class.init_judge_count();
                Class.init_verify_count();
            });
            $('#right_chart_tab_2_li').click(function () {
                console.log(ready.right_chart_tab_width, ready.right_chart_tab_height);
                var opt = {
                    width: ready.right_chart_tab_width,
                    height: ready.right_chart_tab_height,
                    silent: false
                };
                ready.right_chart_tab_2.resize(opt);
            });
            $('.group-title-user-name').find('span').eq(1).html(realName);
            var court = base.get_court(r.user_court_uid);
            $('.group-title-user-court').find('span').eq(1).html(court.shortname);

            // var vlc = getVLC("vlc");
            // if (vlc) {
            //     vlc.playlist.add(r.base_path+'assets/1212.mp4');
            //     vlc.playlist.play();
            //     vlc.audio.volume = 100
            //     var play = $('.audioplayer-playpause').find('a');
            //     console.log(play.html());
            //     if(play.html()=='Play'){
            //         play.click();
            //     }
            // }

            $(window).resize(function () {
                Class.draw();
            });
            // $('#judge_trial_url').attr('href',r.base_path+'views/judge_trial.html?court='+r.court_id);
        }

        function init_ready() {//初始化预设值
            ready.right_chart_tab_2 = echarts.init(document.getElementById('right-chart-tab-2'), "macarons");
            ready.right_chart_tab_width = $('#right-chart-tab-1').width();
            ready.right_chart_tab_height = $('#right-chart-tab-1').height();
            ready.webSocket =
                new WebSocket('ws://' + r.websocket_ip + ':8080/cmp/vodWebSocket');

            ready.webSocket.onerror = function (event) {
                console.info(event);
            };

            ready.webSocket.onopen = function (event) {
                // webSocket.send(data);
            };

            ready.webSocket.onmessage = function (event) {
                if (event.data == 'oauth/signOut') {
                    base.logout();
                }
            };

            window.onbeforeunload = function () {
                ready.webSocket.close();
            };
        }
    };
    //内部调用的方法写这里
    var Class = {
        draw: function () {
            //随着窗口大小改变 动态计算布局
            //设置第一块高度
            var window_height = $(window).height();
            var index_left_height = window_height - 325;
            $('#cmp-left-tabs-content').css('height', index_left_height + 'px');
            //设置第一块内元素边距
            var left_tab = ['left-tab-1', 'left-tab-2', 'left-tab-3'];
            $(left_tab).each(function (index, tab_id) {
                var tab = $('#' + tab_id);
                var tabs_li = tab.find('.media-list li');//获取所有条目
                var tabs_li_height = (index_left_height - 44) / 5;//计算每条所占大小
                if (tabs_li_height > 180) {//实际高度不能超过 180
                    tabs_li_height = 180;
                }
                tabs_li.css('height', tabs_li_height + 'px');//设置条目高度
                tabs_li.find('.cmp-left-media-item').css('margin-top', ((tabs_li_height - 30 - 100 ) / 2) + 'px');//每条目所占高度减去实际高度 等于边距高度
            });
            $('.media-list-with-divider').css('height', index_left_height - 40 + 'px');

            var left_img_width = $('.cmp-left-media-item img').actual('width');
            if (left_img_width >= 215) {
                var left_item_width = $('.cmp-left-media-item').actual('width');
                $('.cmp-left-media-item-content').css('width', left_item_width - 263 + 'px');
            }
            //设置第二块高度
            var index_center_height = window_height - 748;
            var cmp_center_panel = $('#cmp-center-tabs-content');
            cmp_center_panel.css('height', index_center_height + 'px');
            //设置第三块高度
            var index_right_height = window_height - 226;
            $('#cmp-right').css('height', index_right_height + 'px');
            ready.right_chart_tab_width = $('#right-chart-tab-1').width();
            ready.right_chart_tab_height = $('#right-chart-tab-1').height();
        },
        select_dept_group: function () {
            if (deptAndPost) {
                ready.init_data = deptAndPost;

                var dropmenu_dept = $('#dropmenu_dept').find('ul').empty();
                dropmenu_dept.append('<li><a href="javascript:;" onclick="p.dept_change(\'sometimes_everything_is_ok\')">所有部门</a></li>');
                if (deptAndPost.length > 0) {
                    $.each(deptAndPost, function (index, dept) {
                        if (dept.deptId && ready.dept.indexOf(dept.deptId) < 0) {
                            ready.dept.push(dept.deptId);
                            ready.dept_name.push(dept.deptName);
                            dropmenu_dept.append('<li><a href="javascript:;" onclick="p.dept_change(\'' + dept.deptId + '\')">' + dept.deptName + '</a></li>');
                        }
                    })
                } else {
                    $('#dropmenu_dept').find('a').eq(0).html('无部门');
                    $('#dropmenu_judge').find('a').eq(0).html('无法官');
                }

                var dropmenu_judge = $('#dropmenu_judge').find('ul').empty();
                dropmenu_judge.append('<li><a href="javascript:;" onclick="p.judge_change(\'sometimes_everything_is_ok\')">所有法官</a></li>');
                var dropmenu_courtroom = $('#dropmenu_courtroom').find('ul').empty();
                dropmenu_courtroom.append('<li><a href="javascript:;" onclick="p.courtroom_change(\'do_anything_you_want_to_do\')">所有法庭</a></li>');
                if (deptAndPost) {

                    $.each(deptAndPost, function (index, dept) {
                        if (dept.userUid && "法官" == dept.postName) {
                            ready.judge.push(dept.userUid);
                            ready.judge_name.push(dept.userName);
                            if (ready.now_judge.indexOf(dept.userUid) < 0) {
                                ready.now_judge.push(dept.userUid);
                                ready.now_judge_name.push(dept.userName);
                                dropmenu_judge.append('<li><a href="javascript:;" onclick="p.judge_change(\'' + dept.userUid + '\')">' + dept.userName + '</a></li>');
                            }
                        }
                    })
                } else {
                    $('#dropmenu_dept').find('a').eq(0).html('无部门');
                    $('#dropmenu_judge').find('a').eq(0).html('无法官');
                }
                if (courtroomList) {
                    $.each(courtroomList, function (index, courtroom) {
                        dropmenu_courtroom.append('<li><a href="javascript:;" onclick="p.courtroom_change(\'' + courtroom.uid + '\')">' + courtroom.name + '</a></li>');
                        ready.courtrooms.push(courtroom.uid);
                        ready.courtrooms_name.push(courtroom.name);
                    })
                } else {
                    $('#dropmenu_courtroom').find('a').eq(0).html('无法庭');
                }
                if (ready.courtrooms.length > 0) {//ready.judge.length > 0 &&
                    Class.init_case_today_first(ready.judge, null);
                    Class.init_total();//初始化顶部统计栏
                    Class.init_judge_count();//初始化右统计栏
                    Class.init_count_time();
                    Class.init_judge_ranking();
                    Class.init_verify_count();
                } else {
                    layui.use('layer', function () {
                        layui.layer.msg("没有相关数据,请先配置管理的法官!");
                    });
                }

            }
        },
        init_total: function () {//TODO 顶部栏需要修改
            var anime = show_anime(50);
            if (archivesStatistical) {
                setTimeout(function () {
                    anime.close();
                    show(archivesStatistical);
                }, 1000);//1秒后加载 后续优化可以去除
            }

            function show(data) {
                //总容量
                var file_size_total = parseInt(data.openCourtSize);
                var file_size_total_arr = format(file_size_total);
                var cmp_plugins_title_size_span = $('.cmp-plugins-title-size span');
                cmp_plugins_title_size_span.eq(0).html(file_size_total_arr[0]);
                cmp_plugins_title_size_span.eq(1).html(file_size_total_arr[1]);
                cmp_plugins_title_size_span.eq(2).html(file_size_total_arr[2]);
                cmp_plugins_title_size_span.eq(3).html(file_size_total_arr[3]);
                //闭庭数
                var closed_court_total_arr = format(data.openCourtNum);
                var cmp_plugins_title_closed_span = $('.cmp-plugins-title-closed span');
                cmp_plugins_title_closed_span.eq(0).html(closed_court_total_arr[0]);
                cmp_plugins_title_closed_span.eq(1).html(closed_court_total_arr[1]);
                cmp_plugins_title_closed_span.eq(2).html(closed_court_total_arr[2]);
                cmp_plugins_title_closed_span.eq(3).html(closed_court_total_arr[3]);
                //开庭数
                var open_court_time_total_arr = format(data.nowCourting);
                var cmp_plugins_title_open_court = $('.cmp-plugins-title-open-court span');
                cmp_plugins_title_open_court.eq(0).html(open_court_time_total_arr[0]);
                cmp_plugins_title_open_court.eq(1).html(open_court_time_total_arr[1]);
                cmp_plugins_title_open_court.eq(2).html(open_court_time_total_arr[2]);
                cmp_plugins_title_open_court.eq(3).html(open_court_time_total_arr[3]);
                //法庭总数
                var court_room_total_arr = format(data.allCourtNum);
                var cmp_plugins_title_court = $('.cmp-plugins-title-court span');
                cmp_plugins_title_court.eq(0).html(court_room_total_arr[0]);
                cmp_plugins_title_court.eq(1).html(court_room_total_arr[1]);
                cmp_plugins_title_court.eq(2).html(court_room_total_arr[2]);
                cmp_plugins_title_court.eq(3).html(court_room_total_arr[3]);
                //科技法庭数
                var technology_court_total_arr = format(data.technicalCourtNum);
                var cmp_plugins_title_technology = $('.cmp-plugins-title-technology span');
                cmp_plugins_title_technology.eq(0).html(technology_court_total_arr[0]);
                cmp_plugins_title_technology.eq(1).html(technology_court_total_arr[1]);
                cmp_plugins_title_technology.eq(2).html(technology_court_total_arr[2]);
                cmp_plugins_title_technology.eq(3).html(technology_court_total_arr[3]);
                //总时长
                var count_court_now_total_arr = format(Math.round(data.openCourtTime / 24));
                var cmp_plugins_title_now = $('.cmp-plugins-title-now span');
                cmp_plugins_title_now.eq(0).html(count_court_now_total_arr[0]);
                cmp_plugins_title_now.eq(1).html(count_court_now_total_arr[1]);
                cmp_plugins_title_now.eq(2).html(count_court_now_total_arr[2]);
                cmp_plugins_title_now.eq(3).html(count_court_now_total_arr[3]);
            }

            function show_anime(delaytime) {
                if (!delaytime) {
                    delaytime = 100;
                }
                var anime_it = setInterval(function () {
                    var data = {};
                    data.fileSizeTotal = get_random_arr() * 1024 * 1024;
                    data.closedCourtTotal = get_random_arr();
                    data.openCourtTimeTotal = get_random_arr();
                    data.courtRoomTotal = get_random_arr();
                    data.technologyCourtTotal = get_random_arr();
                    data.countCourtNowTotal = get_random_arr();
                    show(data);
                }, delaytime);
                return {
                    close: function () {
                        clearInterval(anime_it);
                    }
                };
                function get_random_arr() {
                    return Math.floor(Math.random() * 10000);
                }
            }

            /**
             * 将数据拆分，转换成4位字符串数组，不足补0。
             * @param num 需要转换的数据
             * @return [*] 4位字符数组
             */
            function format(num) {
                var result_arr = ['0', '0', '0', '0'];
                if (!num) {
                    return result_arr;
                }
                num = num + '';
                var num_arr = num.split('');
                for (var i = 3, j = 3; i > -1; i--) {
                    if (num_arr[i]) {
                        result_arr[j] = num_arr[i];
                        j--;
                    }
                }
                return result_arr;
            }
        },
        dept_change: function (dept_uid) {
            console.info(dept_uid);
            ready.now_judge = [];
            ready.now_judge_name = [];
            ready.now_one_judge = "sometimes_everything_is_ok";
            var dropmenu_judge = $('#dropmenu_judge').find('ul').empty();
            dropmenu_judge.append('<li><a href="javascript:;" onclick="p.judge_change(\'sometimes_everything_is_ok\')">所有法官</a></li>');
            $('#dropmenu_judge').find('a').eq(0).html('所有法官 <span class="caret"></span>');
            if (dept_uid == 'sometimes_everything_is_ok') {
                ready.now_dept = null;
                $('#dropmenu_dept').find('a').eq(0).html('所有部门 <span class="caret"></span>');
                $.each(deptAndPost, function (index, dept) {
                    if (dept.userUid && "法官" == dept.postName) {
                        if (ready.now_judge.indexOf(dept.userUid) < 0) {
                            ready.now_judge.push(dept.userUid);
                            ready.now_judge_name.push(dept.userName);
                            dropmenu_judge.append('<li><a href="javascript:;" onclick="p.judge_change(\'' + dept.userUid + '\')">' + dept.userName + '</a></li>');
                        }
                    }
                })

            } else {
                ready.now_dept = dept_uid;
                var dept_no = null;
                $.each(ready.dept, function (index, ele) {
                    if (ele == dept_uid) {
                        dept_no = index;
                    }
                });
                console.info(ready.dept, ready.dept_name, dept_no);
                $('#dropmenu_dept').find('a').eq(0).html(ready.dept_name[dept_no] + ' <span class="caret"></span>');
                $.each(deptAndPost, function (index, dept) {
                    if (dept.deptId == dept_uid) {
                        if (dept.userUid && "法官" == dept.postName) {
                            if (ready.now_judge.indexOf(dept.userUid) < 0) {
                                ready.now_judge.push(dept.userUid);
                                ready.now_judge_name.push(dept.userName);
                                dropmenu_judge.append('<li><a href="javascript:;" onclick="p.judge_change(\'' + dept.userUid + '\')">' + dept.userName + '</a></li>');
                            }
                        }
                    }
                });
            }
            var dropmenu_courtroom = $('#dropmenu_courtroom').find('a').eq(0).html();
            dropmenu_courtroom = dropmenu_courtroom.replace('<span class="caret"></span>', '').trim();
            if (ready.courtrooms_name.indexOf(dropmenu_courtroom) > 0) {
                $.each(ready.courtrooms_name, function (courtroom_no, courtroom) {
                    if (courtroom == dropmenu_courtroom) {
                        var temp_courtroom = ready.courtrooms[courtroom_no];
                        if (null == ready.now_dept) {
                            Class.init_case_today(null, temp_courtroom);
                        } else {
                            Class.init_case_today(ready.now_judge, temp_courtroom);
                        }
                    }
                });
            } else {
                if (null == ready.now_dept) {
                    Class.init_case_today(null, null);
                } else {
                    Class.init_case_today(ready.now_judge, null);
                }
            }

        },
        judge_change: function (judge_uid) {
            var temp_judge = [judge_uid];
            ready.now_one_judge = judge_uid;
            if (judge_uid == 'sometimes_everything_is_ok') {
                $('#dropmenu_judge').find('a').eq(0).html('所有法官 <span class="caret"></span>');
                if (null == ready.now_dept) {
                    temp_judge = null;
                } else {
                    temp_judge = ready.now_judge;
                }

            } else {
                $.each(ready.judge, function (judge_no, judge) {
                    if (judge == judge_uid) {
                        $('#dropmenu_judge').find('a').eq(0).html(ready.judge_name[judge_no] + ' <span class="caret"></span>');
                    }
                });
            }
            var dropmenu_courtroom = $('#dropmenu_courtroom').find('a').eq(0).html();
            dropmenu_courtroom = dropmenu_courtroom.replace('<span class="caret"></span>', '').trim();
            if (ready.courtrooms_name.indexOf(dropmenu_courtroom) > -1) {
                $.each(ready.courtrooms_name, function (courtroom_no, courtroom) {
                    if (courtroom == dropmenu_courtroom) {
                        var temp_courtroom = ready.courtrooms[courtroom_no];
                        Class.init_case_today(temp_judge, temp_courtroom);
                    }
                });
            } else {
                Class.init_case_today(temp_judge, null);
            }

        },
        courtroom_change: function (courtroom_uid) {
            var temp_courtroom = courtroom_uid;
            if (courtroom_uid == 'do_anything_you_want_to_do') {
                $('#dropmenu_courtroom').find('a').eq(0).html('所有法庭 <span class="caret"></span>');
//                temp_courtroom = ready.courtrooms;
                temp_courtroom = null;
            } else {
                $.each(ready.courtrooms, function (courtroom_no, courtroom) {
                    if (courtroom == courtroom_uid) {
                        $('#dropmenu_courtroom').find('a').eq(0).html(ready.courtrooms_name[courtroom_no] + ' <span class="caret"></span>');
                    }
                });
            }
            // var judge_name = $('#dropmenu_judge').find('a').eq(0).html();
            // judge_name = judge_name.replace('<span class="caret"></span>', '').trim();
            if ("sometimes_everything_is_ok" != ready.now_one_judge && null != ready.now_one_judge) {
                var temp_judge = [];
                temp_judge.push(ready.now_one_judge);
                Class.init_case_today(temp_judge, temp_courtroom);
            } else if (null == ready.now_dept) {
                Class.init_case_today(null, temp_courtroom);
            } else {
                Class.init_case_today(ready.now_judge, temp_courtroom);
            }
        },
        init_case_today: function (judge, court_room) {
            if (judge) {
                judge = judge.toString();
            }
            // judge = judge.toString();
//            court_room = court_room.toString();
            if (null != ready.now_dept && !judge) {
                var left_tab_1 = $('#left-tab-1');
                left_tab_1.find('.media-list').empty();
                left_tab_1.find('.media-list').html("部门无法官");

                var left_tab_2 = $('#left-tab-2');
                left_tab_2.find('.media-list').empty();
                left_tab_2.find('.media-list').html("部门无法官");
            } else {
                $.post(r.base_path + 'judge/selectJudgeCasePlanOrReview', {
                    courtUid: r.user_court_uid,
                    startDate: utils.get_date(0),
                    judgeList: judge,
                    courtRoom: court_room,
                    page: 1,
                    pageSize: 5,
                    review: 0
                }, function (result) {
                    $('#left-tab-1').find('.media-list').empty();
                    var left_tab_1 = $('#left-tab-1');
                    left_tab_1.find('.media-list').empty();
                    left_tab_1.find('.cmp-left-tabs-link a').attr('href', r.base_path + 'archives/more_courting');
                    if (result && result.code == 0) {
                        if (result.data == null) {
                            return;
                        }
                        $(result.data).each(function (index, elem) {
                            var startDate = elem.startDate;
                            var uri = encodeURI(r.base_path + "archives/living?planUid=" + elem.planUid + "&courtroomUid=" + elem.courtroomUid);
                            left_tab_1.find('.media-list').append('<li class="media media-lg">' +
                                '<a href="' + uri + '"><div class="cmp-left-media-item">' +
                                '<div class="cmp-left-media-item-img">' +
                                '<span class="cmp-left-media-item-status">' + elem.statusName + '</span>' +
                                '<img src="' + r.base_path + 'assets/img/list_test2.jpg"/>' +
                                '</div>' +
                                '<div class="cmp-left-media-item-content">' +
                                '<p class="cmp-left-media-item-p cmp-left-media-item-title">' + (elem.name ? elem.name : '未知') + '</p>' +
                                '<p class="cmp-left-media-item-p cmp-left-media-item-addr">开庭地点：' + (elem.courtroomName ? elem.courtroomName : '未知') + '</p>' +
                                '<p class="cmp-left-media-item-p">' +
                                '<span class="cmp-left-media-item-type">' + (elem.typeName ? elem.typeName : '未知') + '</span>' +
                                '<span class="cmp-left-media-item-time"><i class="fa fa-clock-o"></i>' + startDate + '</span>' +
                                '</p>' +
                                '</div>' +
                                '</div></a>' +
                                '</li>');
                        });
                        Class.draw();
                    }
                }, 'json');
                $.post(r.base_path + 'judge/selectJudgeCasePlanOrReview', {
                    courtUid: r.user_court_uid,
                    judgeList: judge,
                    startDate: utils.get_date(0),
                    courtRoom: court_room,
                    page: 1,
                    pageSize: 5,
                    review: 1
                }, function (result) {
                    var left_tab_2 = $('#left-tab-2');
                    left_tab_2.find('.media-list').empty();
                    left_tab_2.find('.cmp-left-tabs-link a').attr('href', r.base_path + "archives/more_review");
                    if (result && result.code == 0) {
                        if (result.data == null) {
                            console.log('无开庭')
                        }
                    }
                    $(result.data).each(function (index, elem) {
                        var startDate = elem.startDate;
                        var uri = encodeURI(r.base_path + "archives/play?planUid=" + elem.planUid);
                        left_tab_2.find('.media-list').append('<li class="media media-lg">' +
                            '<a href="' + uri + '"><div class="cmp-left-media-item">' +
                            '<div class="cmp-left-media-item-img">' +
                            '<img src="' + r.base_path + 'assets/img/list_test2.jpg"/>' +
                            '</div>' +
                            '<div class="cmp-left-media-item-content">' +
                            '<p class="cmp-left-media-item-p cmp-left-media-item-title">' + (elem.name ? elem.name : '未知') + '</p>' +
                            '<p class="cmp-left-media-item-p cmp-left-media-item-addr">开庭地点：' + (elem.courtroomName ? elem.courtroomName : '未知') + '</p>' +
                            '<p class="cmp-left-media-item-p">' +
                            '<span class="cmp-left-media-item-type">' + (elem.typeName ? elem.typeName : '未知') + '</span>' +
                            '<span class="cmp-left-media-item-time"><i class="fa fa-clock-o"></i>' + startDate + '</span>' +
                            '</p>' +
                            '</div>' +
                            '</div></a>' +
                            '</li>');
                    });
                    Class.draw();
                }, 'json').fail(function () {

                });
            }
        },
        init_case_today_first: function (judge, court_room) {
            $('#left-tab-1').find('.media-list').empty();
            var left_tab_1 = $('#left-tab-1');
            left_tab_1.find('.media-list').empty();
            if (moreCourting.length > 0) {
                $(moreCourting).each(function (index, elem) {
                    var startDate = elem.startDate;
                    var statusName = null;
                    if ("0" == elem.status) {
                        statusName = "排期";
                    } else if ("1" == elem.status || 5 == status) {
                        statusName = "开庭";
                    } else if ("2" == elem.status) {
                        statusName = "休庭";
                    } else if ("3" == elem.status) {
                        statusName = "闭庭";
                    } else {
                        statusName = "归档";
                    }
                    var uri = encodeURI(r.base_path + "archives/living?planUid=" + elem.planUid + "&courtroomUid=" + elem.courtroomUid);
                    left_tab_1.find('.media-list').append('<li class="media media-lg">' +
                        '<a href="' + uri + '"><div class="cmp-left-media-item">' +
                        '<div class="cmp-left-media-item-img">' +
                        '<span class="cmp-left-media-item-status">' + statusName + '</span>' +
                        '<img src="' + r.base_path + 'assets/img/list_test2.jpg"/>' +
                        '</div>' +
                        '<div class="cmp-left-media-item-content">' +
                        '<p class="cmp-left-media-item-p cmp-left-media-item-title">' + (elem.name ? elem.name : '未知') + '</p>' +
                        '<p class="cmp-left-media-item-p cmp-left-media-item-addr">开庭地点：' + (elem.courtroomName ? elem.courtroomName : '未知') + '</p>' +
                        '<p class="cmp-left-media-item-p">' +
                        '<span class="cmp-left-media-item-type">' + (elem.typeName ? elem.typeName : '未知') + '</span>' +
                        '<span class="cmp-left-media-item-time"><i class="fa fa-clock-o"></i>' + startDate + '</span>' +
                        '</p>' +
                        '</div>' +
                        '</div></a>' +
                        '</li>');
                });
            }
            left_tab_1.find('.cmp-left-tabs-link a').attr('href', r.base_path + 'archives/more_courting');
            Class.draw();

            var left_tab_2 = $('#left-tab-2');
            left_tab_2.find('.media-list').empty();
            $(moreReview).each(function (index, elem) {
                var startDate = elem.startDate;
                var uri = encodeURI(r.base_path + "archives/play?planUid=" + elem.planUid);
                left_tab_2.find('.media-list').append('<li class="media media-lg">' +
                    '<a href="' + uri + '"><div class="cmp-left-media-item">' +
                    '<div class="cmp-left-media-item-img">' +
                    '<img src="' + r.base_path + 'assets/img/list_test2.jpg"/>' +
                    '</div>' +
                    '<div class="cmp-left-media-item-content">' +
                    '<p class="cmp-left-media-item-p cmp-left-media-item-title">' + (elem.name ? elem.name : '未知') + '</p>' +
                    '<p class="cmp-left-media-item-p cmp-left-media-item-addr">开庭地点：' + (elem.courtroomName ? elem.courtroomName : '未知') + '</p>' +
                    '<p class="cmp-left-media-item-p">' +
                    '<span class="cmp-left-media-item-type">' + (elem.typeName ? elem.typeName : '未知') + '</span>' +
                    '<span class="cmp-left-media-item-time"><i class="fa fa-clock-o"></i>' + startDate + '</span>' +
                    '</p>' +
                    '</div>' +
                    '</div></a>' +
                    '</li>');
            });
            left_tab_2.find('.cmp-left-tabs-link a').attr('href', r.base_path + "archives/more_review");
            Class.draw();
        },
        init_judge_count: function (pageIndex) {
            if (!pageIndex) {
                pageIndex = 1;
            }
            //获取时间
            var end_time = $("#endTime").find("input").val();
            var start_time = $("#startTime").find("input").val();
            ready.count_start_time = start_time;
            ready.count_end_time = end_time;
            //获取案号
            var case_no = $("#caseno").val();
            //获取当前选择的法官
            var temp_judge = [];
            var selected_judge_name = $("#dropmenu_judge a:first").html().replace('<span class="caret"></span>', '').trim();
            // if (ready.judge_name.indexOf(selected_judge_name) > -1) {
            if ("sometimes_everything_is_ok" != ready.now_one_judge && null != ready.now_one_judge) {
                temp_judge.push(ready.now_one_judge);
            } else if (null == ready.now_dept) {
                temp_judge = null;
            } else {
                temp_judge = ready.now_judge;
            }
            //获取当前法庭Id
            var temp_courtroom = null;
            var selected_courtroom_name = $("#dropmenu_courtroom a:first").html().replace('<span class="caret"></span>', '').trim();
            if (ready.courtrooms_name.indexOf(selected_courtroom_name) > -1) {
                $.each(ready.courtrooms_name, function (courtroom_no, courtroom) {
                    if (courtroom == selected_courtroom_name) {
                        temp_courtroom = ready.courtrooms[courtroom_no];
                    }
                });
            }

            if (temp_judge) {
                temp_judge = temp_judge.toString();
            }
            if (ready.status_value == "2") {
                $("#right-list-tab-1").html("");
                $("#right-list-tab-1").append('<span>暂无数据</span>');
            } else if (ready.now_dept != null && ready.now_judge.length == 0) {
                $("#right-list-tab-1").html("");
                $("#right-list-tab-1").append('<span>部门没有法官</span>');
            } else {
                $.get(r.base_path + 'judge/selectMoreCasePlanOrReview', {
                    judgeList: temp_judge,
                    courtUid: r.user_court_uid,
                    courtRoom: temp_courtroom,
                    startDate: start_time,
                    endDate: end_time,
                    archives: case_no,
                    review: ready.status_value,
                    status: 0,
                    page: pageIndex,
                    pageSize: 5
                }, function (result) {
                    if (result.code == 1) {
                        $("#right-list-tab-1").html("");
                        $("#right-list-tab-1").append('<span>无数据</span>');
                        return;
                    }
                    $("#right-list-tab-1").html("");

                    $("#right-list-tab-1").append('<table id="table" class="table table-bordered context-span context-white cursor-hand"></table>');
                    $("#right-list-tab-1").append('<div id="_page"></div>');
                    ready.more_review_trial = result.data.trialList;
                    var sum = result.data.count;
                    if (sum == 0) {
                        page(1, 1, null);
                    } else {
                        page(pageIndex, Math.ceil(sum / 5), Class.init_judge_count);
                    }


                    $('#table').bootstrapTable({
//			    	paginationLoop:true,
                        columns: [{
                            field: 'courtroomName',
                            title: '法庭'
                        }, {
                            field: 'judgeName',
                            title: '法官'
                        }, {
                            field: 'archives',
                            title: '案件号'
                        }, {
                            field: 'name',
                            title: '案件名称'
                        }, {
                            field: 'summary',
                            title: '概要'
                        }, {
                            field: 'startDate',
                            title: '开庭时间'
                        }
                        ],
                        data: result.data.data,
                        onClickRow: function (row) {
                            var trialUid = null;

                            if (ready.status_value == 1) {
                                var tempTrialList = [];
                                $.each(ready.more_review_trial, function (index, elem) {
                                    if (elem.planUid == row.planUid && elem.status != 0 && elem.status != 1) {
                                        tempTrialList.push(elem);
                                    }
                                });
                                if (tempTrialList.length > 1) {
                                    $("#select_video_table").empty();
                                    $.each(tempTrialList, function (index, elem) {
                                        var start_date = new Date(elem.startDate);
                                        start_date = start_date.getFullYear() + '-' + (start_date.getMonth() + 1) + '-' + start_date.getDate() + ' ' + start_date.getHours() + ':' + start_date.getHours();
                                        var tr = "<tr class='cursor-hand' onclick='p.selectVideoTrial(\"" + elem.uid + "\",\"" + row.planUid + "\",\"" + row.courtUid + "\")'><td style='border:1px solid blue;text-align:center;height:40px;color:black'>第" + (index + 1) + "次开庭</td><td style='border:1px solid blue;text-align:center;height:40px;color:black'>" + start_date + "</td></tr>";
                                        $("#select_video_table").append(tr);

                                    });

                                    /* 完成拖拽 */
                                    $("#select_video").draggable({
                                        cursor: "move",
                                        handle: '.modal-header'//--指定只有拖拽头部，才能拖拽
                                    });
                                    //显示模态框
                                    $("#select_video").modal("show");
                                } else {
                                    trialUid = tempTrialList[0].uid;
                                    Class.getCaseInfoById(row.planUid, trialUid);
                                    Class.getCourtrecForId(trialUid, row.courtUid);
                                    Class.getInfo(trialUid);
                                }
                            } else {
                                $.each(ready.more_review_trial, function (index, elem) {
                                    if (elem.planUid == row.planUid && (elem.status == 0 || elem.status == 1 || elem.status == 5)) {
                                        trialUid = elem.uid;
                                    }
                                });
                                Class.getCaseInfoById(row.planUid, trialUid);
                                if (row.status == 1 || row.status == 5) {
                                    getCgf(row.planUid, row.courtroomUid, base.get_court(r.user_court_uid).serviceIp);
                                }
                            }
                        }
                    });
                    $('#table').bootstrapTable("load", result.data);
                    $('#table').bootstrapTable("hideLoading");

                }, 'json').fail(function () {
                    alert("查询失败");
                });
            }

        },
        selectVideoTrial: function (trialUid, planUid, courtUid) {
            //显示模态框
            $("#select_video").modal("hide");
            Class.getCaseInfoById(planUid, trialUid);
            Class.getCourtrecForId(trialUid, courtUid);
            Class.getInfo(trialUid);

        },
        init_verify_count: function (pageIndex) {
            if (!pageIndex) {
                pageIndex = 1;
            }
            //获取案号
            var case_no = $("#caseno").val();
            //获取当前选择的法官
            var temp_judge = [];
            var selected_judge_name = $("#dropmenu_judge a:first").html().replace('<span class="caret"></span>', '').trim();
            // if (ready.judge_name.indexOf(selected_judge_name) > -1) {
            if ("sometimes_everything_is_ok" != ready.now_one_judge && null != ready.now_one_judge) {
                temp_judge.push(ready.now_one_judge);
            } else if (null == ready.now_dept) {
                temp_judge = [];
            } else {
                temp_judge = ready.now_judge;
            }
            var end_time = $("#endTime").find("input").val();
            var start_time = $("#startTime").find("input").val();
            $.post(r.base_path + "image/selectJudgeImageByCondition", {
                startDate: start_time,
                endDate: end_time,
                archives: case_no,
                judgeList: temp_judge.toString(),
                page: pageIndex,
                pageSize: 5,
                courtUid: r.user_court_uid
            }, function (result) {
                if (result.data.count <= 0) {
                    $("#right-list-tab-2").html("");
                    $("#right-list-tab-2").append('<span>无数据</span>');
                    return;
                }
                $("#right-list-tab-2").html("");

                $("#right-list-tab-2").append('<table id="table2" class="table table-bordered context-span context-white cursor-hand"></table>');
                $("#right-list-tab-2").append('<div id="_page2"></div>');

                var sum = result.data.count;
                if (sum == 0) {
                    page2(1, 1, null);
                } else {
                    page2(pageIndex, Math.ceil(sum / 5), Class.init_verify_count);
                }

                $('#table2').bootstrapTable({
//			    	paginationLoop:true,
                    columns: [{
                        field: 'caseArchives',
                        title: '案号',
                        width: '25%'
                    }, {
                        field: 'channelsName',
                        title: '通道名称',
                        width: '9%'
                    }, {
                        field: 'judgeName',
                        title: '案件法官',
                        width: '9%'
                    }, {
                        field: 'creatUserName',
                        title: '创建人',
                        width: '9%'
                    }, {
                        field: 'type',
                        title: '类型',
                        width: '9%',
                        formatter: function (result) {
                            if (result == 1) {
                                return '图片';
                            } else {
                                return '视频';
                            }
                        }
                    }, {
                        field: 'dateCreated',
                        title: '创建时间',
                        width: '12%',
                        formatter: function (result) {
                            var date = new Date(result);
                            var seperator1 = "-";
                            var seperator2 = ":";
                            var month = date.getMonth() + 1;
                            if (month >= 1 && month <= 9) {
                                month = "0" + month;
                            }
                            var strDate = date.getDate();
                            if (strDate >= 1 && strDate <= 9) {
                                strDate = "0" + strDate;
                            }
                            var hours = date.getHours();
                            //时
                            if (hours >= 0 && hours <= 9) {
                                hours = "0" + hours;
                            }
                            var minute = date.getMinutes();
                            //分
                            if (minute >= 0 && minute <= 9) {
                                minute = "0" + minute;
                            }
                            //秒
                            var second = date.getSeconds();
                            //分
                            if (second >= 0 && second <= 9) {
                                second = "0" + second;
                            }
                            var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
                                + " " + hours + seperator2 + minute + seperator2 + second;
                            return currentdate;
                        }
                    }, {
                        field: 'startTimeStr',
                        title: '截取起点',
                        width: '12%'
                    }, {
                        field: 'endTimeStr',
                        title: '截取终点',
                        width: '12%'
                    }, {
                        field: '',
                        title: '下载',
                        width: '10%',
                        formatter: function (result, row) {
                            var url = "http://" + location.hostname + ":8200/";
                            var a = "<a href='" + url + row.path + "'><button class='btn btn-primary'>下载</button></a>"
                            // var b = "<button class='btn btn-primary' onclick='del(this);' id='" + row.id + "'>删除</button>";
                            return a;
                        }
                    }],
                    data: result.data.data,
                    onClickRow: function (row) {
                    }
                });
                $('#table2').bootstrapTable("load", result.data.data);
                $('#table2').bootstrapTable("hideLoading");
            }, 'json').fail(function () {
                alert("查询失败");
            });
        },
        init_count_time: function () {
            //获得时间月份数组
            var now = new Date();
            var month = now.getMonth() + 1;
            var start_time = null;
            if (month >= 7) {
                var start_month = month - 6;
                start_time = now.getFullYear() + "-0" + start_month;
            } else {
                var start_month = 12 + month - 6;
                if (start_month < 10) {
                    start_time = now.getFullYear() - 1 + "-0" + start_month;
                } else {
                    start_time = now.getFullYear() - 1 + "-" + start_month;
                }
            }
            if (month < 10) {
                month = "0" + month;
            }
            var end_time = now.getFullYear() + "-" + month;
            var time_arr = [start_time];
            for (var i = 0; i < 5; i++) {
                var last_month = parseInt(time_arr[time_arr.length - 1].substr(5));
                if (last_month < 12) {
                    var temp_month = last_month + 1;
                    if (temp_month < 10) {
                        time_arr.push(time_arr[time_arr.length - 1].substr(0, 4) + "-0" + temp_month);
                    } else {
                        time_arr.push(time_arr[time_arr.length - 1].substr(0, 4) + "-" + temp_month);
                    }
                } else if (last_month == 12) {
                    time_arr.push(parseInt(time_arr[time_arr.length - 1].substr(0, 4)) + 1 + "-01");
                }
            }
            time_arr.push(end_time);
//        	console.info(time_arr);
            $.get(r.base_path + 'judge/getJudgeCourtMonthStatistics', {
                startDate: start_time,
                endDate: end_time,
                judgeUids: null,
                courtUid: r.user_court_uid
            }, function (result) {

                var ydata = [];
                for (var i = 0; i < time_arr.length; i++) {
                    ydata[i] = 0;
                    $.each(result.data.timeMonthStatistics, function (index, elem) {
                        if (time_arr[i] == elem.date) {
                            ydata[i] = elem.timeLong;
                        }
                    });
                }

                var myChart = echarts.init(document.getElementById('right-chart-tab-1'), "shine");
                // 指定图表的配置项和数据
                var option = {
//				    		title: {
//				    			text: "开庭数统计(次)", //正标题
//				    			x: "left", //标题水平方向位置
//				    			textStyle: {
//				    				fontSize:24,
//				    				color:"#FFFFFF"
//				    				}
//				    		},
                    color: ['#D5B136'],
                    /* title:{
                     text:title,
                     textStyle:{
                     color:"#ffffff"
                     }
                     },*/
                    grid: {
                        show: false,
                        left: '9%',
                        right: '6%',
                        top: 30,
                        bottom: 30
                    },
                    tooltip: {},
                    xAxis: {
                        data: time_arr,
                        axisLine: {
                            lineStyle: {
                                color: "#1c4e93"
                            }
                        },
                        axisLabel: {
                            textStyle: {
                                fontSize: 16,
                                color: "#FFFFFF"
                            },
                            // rotate:-30,
                            interval: 0
                        }
                    },
                    yAxis: {
                        axisLine: {
                            lineStyle: {
                                color: "#1c4e93"
                            }
                        },
                        axisLabel: {
                            textStyle: {
                                fontSize: 16,
                                color: "#FFFFFF"
                            },
                            formatter: function (value) {
                                return value + 'h'
                            }
                        }
                    },
                    series: [{
                        name: '开庭时长',
                        //            barWidth: '50%',
                        barMaxWidth: 20,
                        type: 'bar',
                        itemStyle: {
                            normal: {
                                label: {
                                    show: true,
                                    position: 'top',
                                    textStyle: {
                                        color: "#d94600",
                                        fontSize: 20
                                    }
                                }
                            }
                        },
                        data: ydata
                    }]
                };
                // 使用刚指定的配置项和数据显示图表。
                myChart.setOption(option);
                window.onresize = myChart.resize;

            }, 'json').fail(function () {
                alert("查询失败");
            });

        },
        init_judge_ranking: function () {
            var now = new Date();
            var month = now.getMonth() + 1;
            var start_time = null;
            if (month >= 7) {
                var start_month = month - 6;
                start_time = now.getFullYear() + "-0" + start_month;
            } else {
                var start_month = 12 + month - 6;
                if (start_month < 10) {
                    start_time = now.getFullYear() - 1 + "-0" + start_month;
                } else {
                    start_time = now.getFullYear() - 1 + "-" + start_month;
                }
            }
            if (month < 10) {
                month = "0" + month;
            }
            var end_time = now.getFullYear() + "-" + month;
            $.get(r.base_path + 'index/selectJudgeOpenTimeAndOpenNum', {
                startDate: start_time,
                endDate: end_time,
                courtUid: r.user_court_uid
            }, function (result) {

                var sum_judge = [];
                var sum_max = 1;
                $(result.data).each(function (i, elem) {
                    // if (ready.judge.indexOf(elem.userUid) > -1) {
                    elem.openNum > sum_max ? sum_max = elem.openNum : '';
                    var judge = [];
                    judge.push(elem.openNum);
                    judge.push(elem.openTime);
                    judge.push(elem.realName);
                    sum_judge.push(judge);
                    // }
                });
                var option = {
                    grid: [{
                        show: false,
                        left: '9%',
                        right: '6%',
                        top: 30,
                        bottom: 30
                    }],
                    tooltip: {
                        padding: 10,
                        backgroundColor: '#222',
                        borderColor: '#777',
                        borderWidth: 1,
                        formatter: function (obj) {
                            var value = obj.value;
                            return '<div style="border-bottom: 1px solid rgba(255,255,255,.3); font-size: 18px;padding-bottom: 7px;margin-bottom: 7px">' +
                                '姓名：' + value[2] +
                                '</div>' +
                                '开庭次数：' + value[0] + '次<br>' +
                                '开庭时长：' + value[1] + '小时<br>';
                        }
                    },
                    xAxis: {
                        splitLine: {
                            show: false
                        },
                        axisLine: {
                            lineStyle: {
                                color: '#fff'
                            }
                        },
                        axisLabel: {
                            formatter: function (value) {
                                return value + '次'
                            }
                        }
                    },
                    yAxis: {
                        nameTextStyle: {
                            color: '#fff',
                            fontSize: 16
                        },
                        splitNumber: 4,
                        axisLine: {
                            lineStyle: {
                                color: '#eee',
                                show: false
                            }
                        },
                        axisLabel: {
                            formatter: function (value) {
                                return value + 'h'
                            }
                        },
                        splitLine: {
                            show: false
                        },
                        scale: true
                    },

                    series: [{
                        name: '开庭次数',
                        data: sum_judge,
                        type: 'scatter',
                        symbolSize: function (data) {
                            return (data[1] / sum_max) * 25 + 10;
                        },
                        label: {
                            emphasis: {
                                show: true,
                                formatter: function (param) {
                                    return param.data[2];
                                },
                                position: 'top'
                            }
                        },
                        itemStyle: {
                            normal: {
                                color: '#009999'
                            }
                        }
                    }]
                };
                ready.right_chart_tab_2.setOption(option);
                window.onresize = ready.right_chart_tab_2.resize;

            }, 'json').fail(function () {
                alert("查询失败");
            });
        },
        getCaseInfoById: function (uid, trialUid) {
            $.ajax({
                url: r.base_path + "playInfo/getCaseInfoByUid",
                type: "post",
                dataType: "json",
                data: {
                    planUid: uid,
                    trialUid: trialUid
                },
                success: function (result) {
                    if (result.code == 1) {
                        return;
                    }
                    var caseInfo = result.data;
                    var archives = caseInfo.archives;
                    var caseName = caseInfo.caseName;
                    //记录人员点播信息
                    var data = {
                        caseUid: caseInfo.caseUid,
                        userName: $.cookie('_username'),
                        courtUid: r.user_court_uid,
                        userCourtUid: r.user_court_uid,
                        planUid: caseInfo.planUid,
                        archives: archives,
                        name: caseName,
                        type: caseInfo.casetypeName,
                        vod: ready.status_value
                    };
                    data = JSON.stringify(data);
                    ready.webSocket.send(data);

                    var subName = "";
                    var caseTypeName = caseInfo.casetypeName;
                    var judgeUid = caseInfo.judgeUserUid;
                    var secretaryUid = caseInfo.secretaryUserUid;
                    var courtroomName = caseInfo.courtRoomName;
                    var statusName = caseInfo.statusName;
                    var parties = caseInfo.accuse + " " + caseInfo.accused;
                    var startDate = caseInfo.startDate;

                    var endDate = caseInfo.endDate ? caseInfo.endDate : '未知';
                    var caseDesc = caseInfo.casedesc;
                    if (caseDesc == null) {
                        caseDesc = "";
                    }
//		            console.log(result);
//		            $("#title").html('&nbsp;' + caseNo + "——" + caseName);
                    var html = ['  <div class="cmp-play-text">',
                        '                        <div class="row row-court">',
                        '                            <div class="col-md-3 col-xs-4 text-right">',
                        '                                <span> 案  号：</span>',
                        '                            </div>',
                        '                            <div class="col-md-9 col-xs-8 text-left">',
                        '                                <span>' + archives + '</span>',
                        '                            </div>',
                        '                        </div>',
                        '                        <div class="row row-court">',
                        '                            <div class="col-md-3 col-xs-4 text-right">',
                        '                                <span>案件类型：</span>',
                        '                            </div>',
                        '                            <div class="col-md-3 col-xs-8 text-left">',
                        '                                <span>' + caseTypeName + '</span>',
                        '                            </div>',
                        '                        </div>',
                        '                        <div class="row row-court">',
                        '                            <div class="col-md-3 col-xs-4 text-right">',
                        '                                <span>案件名称：</span>',
                        '                            </div>',
                        '                            <div class="col-md-9 col-xs-8 text-left">',
                        '                                <span>' + caseName + '</span>',
                        '                            </div>',
                        '                        </div>',
                        '                        <div class="row row-court">',
                        '                            <div class="col-md-3 col-xs-4 text-right">',
                        '                                <span> 审判长：</span>',
                        '                            </div>',
                        '                            <div class="col-md-3  col-xs-8 text-left">',
                        '                                <span><a id="judge_name" class="white-a">' + (caseInfo.judgeName ? caseInfo.judgeName : '未知') + '</a></span>',
                        '                            </div>',
                        '                            <div class="col-md-3 col-xs-4 text-right">',
                        '                            </div>',
                        '                            <div class="col-md-3  col-xs-8 text-left">',
                        '                            </div>',
                        '                            <div class="col-md-3 col-xs-4 text-right">',
                        '                                <span> 书记员：</span>',
                        '                            </div>',
                        '                            <div class="col-md-3  col-xs-8 text-left">',
                        '                                <span>' + (caseInfo.secretaryName ? caseInfo.secretaryName : '未知') + '</span>',
                        '                            </div>',
                        '                        </div>',
                        '                        <div class="row row-court">',
                        '                            <div class="col-md-3 col-xs-4 text-right">',
                        '                                <span>当事人：</span>',
                        '                            </div>',
                        '                            <div class="col-md-9 col-xs-8 text-left">',
                        '                                <span>' + parties + '</span>',
                        '                            </div>',
                        '                        </div>',
                        '                        <div class="row row-court">',
                        '                            <div class="col-md-3 col-xs-4 text-right">',
                        '                                <span> 开庭地点：</span>',
                        '                            </div>',
                        '                            <div class="col-md-9 col-xs-8 text-left">',
                        '                                <span>' + (courtroomName ? courtroomName : '未知') + '</span>',
                        '                            </div>',
                        '                        </div>',
                        '                        <div class="row row-court">',
                        '                            <div class="col-md-3 col-xs-4 text-right">',
                        '                                <span>开庭时间：</span>',
                        '                            </div>',
                        '                            <div class="col-md-9 col-xs-8 text-left">',
                        '                                <span>' + startDate + '</span>',
                        '                            </div>',
                        '                        </div>',
                        '                        <div class="row row-court">',
                        '                            <div class="col-md-3 col-xs-4 text-right">',
                        '                                <span>闭庭时间：</span>',
                        '                            </div>',
                        '                            <div class="col-md-9 col-xs-8 text-left">',
                        '                                <span>' + endDate + '</span>',
                        '                            </div>',
                        '                        </div>',
                        '                        <div class="row row-court">',
                        '                            <div class="col-md-3 col-xs-4 text-right">',
                        '                                <span> 庭审状态：</span>',
                        '                            </div>',
                        '                            <div class="col-md-3 col-xs-8 text-left">',
                        '                                <span>' + statusName + '</span>',
                        '                            </div>',
                        '                        </div>',
                        '                        <div class="row row-court">',
                        '                            <div class="col-md-3 col-xs-4 text-right">',
                        '                                <span>   基本案情：</span>',
                        '                            </div>',
                        '                            <div class="col-md-9 col-xs-8 text-left">',
                        '                                <span>' + caseDesc + '</span>',
                        '                            </div>',
                        '                        </div>',
                        '                    </div>'].join("");
                    $("#center-tab-1").html("");
                    $("#center-tab-1").append(html);
                    $("#judge_name").attr("href", r.base_path + "archives/more_review?judge=" + judgeUid);
//           			$("#secretary_name").attr("href", r.base_path + encodeURI("views/more_reviewing.html?secretary=" + secretaryName + "&city=" + now_video+'&court='+r.court_id));
                }
            });
        },
        getCourtrecForId: function (trialUid, courtUid) {
            $.post(r.base_path + "video/courtrecForId", {trialUid: trialUid, courtUid: courtUid}, function (result) {
                if (result && result.data) {
                    $("#center-tab-2").html(result.data[0]);
                    //绑定笔录下载地址--基于http下载
//		        	 $("#noteLoad").attr("href",result.data[1]);
                }
            });
        },
        getInfo: function (trialUid) {
            $.ajax({
                url: r.base_path + "video/selectPlayVideo",
                type: 'post',
                async: false,
                dataType: "json",
                data: {
                    trialUid: trialUid,
                    courtUid: r.user_court_uid
                },
                success: function (result) {
                    console.info(result);
                    if (result.code == 0) {
                        if (!result.data || result.data.length == 0) {
                            alert("没有找到点播信息！");
                            return;
                        }
                        //result.data赋值给_data 以后操作_data
                        p._data = result.data;
                        p.now_channel_arr = [];
                        var chn = [];
                        //构造点播通道select
                        var video_row_1 = "";
                        var video_row_2 = "";
                        var count = 0;
                        $.each(p._data, function (i, n) {
                            if (chn.indexOf(n.channelsName) == -1) {
                                if (count < 4) {
                                    video_row_1 += '<div class="col-md-3"><div class="group-left-dropdown" id="' + n.channelsName + '">'
                                        + '        <a href="javascript:;" data-toggle="dropdown" class="btn btn-cmp-dropdown dropdown-toggle">'
                                        + '			<div class="' + n.channelsName + '" >' + n.channelsName + '<span class="caret"></span></div></a> '
                                        + '        	<ul class="dropdown-menu"> '
                                        + '        	</ul> '
                                        + '  </div></div>';  //onclick=get_video_channel(this)
                                } else {
                                    video_row_2 += '<div class="col-md-3"><div class="group-left-dropdown" id="' + n.channelsName + '">'
                                        + '        <a href="javascript:;" data-toggle="dropdown" class="btn btn-cmp-dropdown dropdown-toggle">'
                                        + '			<div class="' + n.channelsName + '" >' + n.channelsName + '<span class="caret"></span></div></a> '
                                        + '        	<ul class="dropdown-menu"> '
                                        + '        	</ul> '
                                        + '  </div></div>';
                                }
                                chn.push(n.channelsName);
                                p.now_channel_arr.push(n.channelsName);
                                count++;
                            }

                            if (n.startRecTime) {
                                var startRecTime = new Date(n.startRecTime);
                                n.startRecTime = (startRecTime.getHours() > 9 ? startRecTime.getHours() : "0" + startRecTime.getHours()) + ":" + (startRecTime.getMinutes() > 9 ? startRecTime.getMinutes() : "0" + startRecTime.getMinutes());
                            } else {
                                n.startRecTime = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                            }
                            if (n.endRecTime) {
                                var endRecTime = new Date(n.endRecTime);
                                n.endRecTime = (endRecTime.getHours() > 9 ? endRecTime.getHours() : "0" + endRecTime.getHours()) + ":" + (endRecTime.getMinutes() > 9 ? endRecTime.getMinutes() : "0" + endRecTime.getMinutes());
                            } else {
                                n.endRecTime = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                            }
                        });
                        $(".group-center-video-type").children("div:eq(0)").html("");
                        $(".group-center-video-type").children("div:eq(1)").html("");
                        $(".group-center-video-type").children("div:eq(0)").html(video_row_1);
                        $(".group-center-video-type").children("div:eq(1)").html(video_row_2);
                        initVideoSelect();
                        //初始化播放信道
                        if (p.now_channel_arr.length > 0) {
                            p.now_channel = p.now_channel_arr[0];
                            get_video_channel(0);
                        }
                    } else {
                        console.log(result.msg);
                    }
                }
            });
        },
        convert_data: function (data) {
            // console.log(typeof data,data);
            var res = [];
            $(data).each(function (index, elem) {
                res.push({
                    name: elem.courtName,
                    value: [parseFloat(elem.lng), parseFloat(elem.lat), elem.total, elem.courtId],
                    color: '#FF7F50',
                    itemStyle: {
                        normal: {
                            textStyle: {
                                fontSize: 16,
                                color: (elem.total > 100 ? '#FF7F50' : '#000')
                            }
                        },
                        emphasis: {
                            textStyle: {
                                color: (elem.total > 100 ? '#FF7F50' : '#000')
                            }
                        }
                    }
                });
            });
            // console.log(res);
            return res;
        }

    };
    init();
    //TODO 对外公开的方法写在这里
    window.p = {
        judge_change: Class.judge_change,
        courtroom_change: Class.courtroom_change,
        dept_change: Class.dept_change,
        _data: null,
        now_channel: null,//记录当前播放的信道
        now_channel_arr: [],
        selectVideoTrial: Class.selectVideoTrial
    };
}(window);

function page(now, totalPages, callback) {
    base.pagination('#_page', {
        currentPage: now,
        totalPages: totalPages,
        onPageClicked: function (page) {
            callback(page);
        }
    });
}
function page2(now, totalPages, callback) {
    base.pagination('#_page2', {
        currentPage: now,
        totalPages: totalPages,
        onPageClicked: function (page) {
            callback(page);
        }
    });
}

function get_video_channel(vlcItem) {
    vlcItem = vlcItem ? vlcItem : 0;
    vlc_playlist = [];
    if (vlc) {
        //防止出现意外时初始化视频号
        $.each(p._data, function (i, n) {
            if (n.channelsName == p.now_channel) {
                vlc_playlist.push(n);
            }
        });
        init_playlist(vlcItem);
    }
}

function initVideoSelect() {
    $.each(p._data, function (j, n) {
        $("#" + n.channelsName).find("ul").append('<li><a href="javascript:;" class="' + n.channelsName + '" onclick="select_video_channel(this)">' + n.startRecTime + '--' + n.endRecTime + '</a></li>');
    });
}
function select_video_channel(val) {
    p.now_channel = $(val).attr("class");
    var vlcItem = $(val).parents("li").parents("ul").find("li").index($(val).parents("li"));
    get_video_channel(vlcItem);
}

function getCgf(uid, cid, courtIp, channel) {
    channel = channel ? channel : 1;
    $(".group-center-video-type").children("div:eq(0)").html("");
    $(".group-center-video-type").children("div:eq(1)").html("");
    $.ajax({
        url: r.base_path + "courtRoom/getCfgInfo",
        type: "post",
        dataType: "json",
        data: {
            courtRoomUid: cid,
            serverIp: courtIp
        },
        success: function (result) {
            if (result != null) {
                var data = result.data;
                var count = 0;
                var video_row_1 = "";
                var video_row_2 = "";
                var d = 0;
                $.each(data, function (index, ele) {
                    if (ele.record == 1) {
                        if (count < 4) {
                            video_row_1 += '<div class="col-md-3"><div>' + ele.name + '</div></div>';  //onclick=get_video_channel(this)
                        } else {
                            video_row_2 += '<div class="col-md-3"><div>' + ele.name + '</div></div>';
                        }
                        count = count + 1;
                        if (count == channel) {
                            d = index;
                        }
                    }
                });
                $(".group-center-video-type").children("div:eq(0)").html(video_row_1);
                $(".group-center-video-type").children("div:eq(1)").html(video_row_2);
                //初始化直播信号
                $(".group-center-video-type").find(".col-md-3").eq(channel - 1).find("div").attr("class", "active");
                var cha = data[d].stream;//默认显示
                initialise(cha);
                $(".group-center-video-type").children("div").children('div').click(function () {
                    var inx = $(".group-center-video-type").find(".col-md-3").index(this) + 1;
                    console.info(inx);
                    getCgf(uid, cid, courtIp, inx);
                });
            }

        },
        error: function () {
        }
    });
}

function initialise(cfg) {
    var vlc = getVLC("vlc");
    if (vlc) {
        vlc.playlist.items.clear();
        while (vlc.playlist.items.count > 0) {
            // clear() may return before the playlist has actually been cleared
            // just wait for it to finish its job
        }
        var options = [":rtsp-tcp"];
        var itemId;
        console.log(cfg);
        itemId = vlc.playlist.add(cfg, "", options);

        if (itemId != -1) {
            vlc.playlist.playItem(itemId);
        } else {
            alert("cannot play at the moment !");
        }
    }
}
